﻿@using Umbraco.Core.Services
@using Umbraco.Web.Controllers
@using Umbraco.Web.Models
@inherits UmbracoTemplatePage
@{
    var homePage = CurrentPage.AncestorsOrSelf(1).First();

    var menuItems = homePage.Children.Where("UmbracoNaviHide == false");

    var logoutModel = new PostRedirectModel();
    logoutModel.RedirectUrl = "/";
}
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Guitar-Greb</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="@(CurrentPage.Url == "/" ? "active" : null)"><a href="/">Heim <span class="sr-only">(current)</span></a></li>
                @foreach (var item in menuItems)
                {
                    <li class="@(CurrentPage.Id == item.Id ? "active" : null)"><a href="@item.Url">@item.Name</a></li>
                }
            </ul>
            <form action="/leitan/" method="get" class="navbar-form navbar-left" role="search">
                <div class="form-group">
                    <input type="text" name="q" value="" class="form-control" placeholder="Leita">
                </div>
                <input value="Leita" type="submit" class="btn btn-default" />
            </form>
            <ul class="nav navbar-nav navbar-right">
                @if (Members.GetCurrentMember() == null)
                {
                    <li><a href="/login">Innrita</a></li>
                    <li><a href="/register">Nýggjur brúkari</a></li>
                }
                else
                {

                    using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
                    {
                        <li><span class=""><i class="glyphicon glyphicon-user"> </i> Hey, @Members.GetCurrentMember().Name<button class=" btn btn-link">Útrita</button></span></li>


                        @Html.HiddenFor(m => logoutModel.RedirectUrl)
                    }
                }
            </ul>
        </div>
    </div>
</nav>